/**
 * 个人js
 */
$(function() {
	initialPage();
	getGrid();
});

function initialPage() {
	$(window).resize(function() {
		$('#dataGrid').bootstrapTable('resetView', {
			height : $(window).height() - 56
		});
	});
}

function getGrid() {
	$('#dataGrid').bootstrapTableEx({
		url : '../../sys/userpersonal/list?_' + $.now(),
		height : $(window).height() - 56,
		queryParams : function(params) {
			params.name = vm.keyword;
			return params;
		},
		columns : [ {
			checkbox : true
		}, {
			field : "createTime",
			title : "创建时间",
			width : "100px"
		}, {
			field : "userName",
			title : "用户名",
			width : "100px"
		},{
			field : "contacts",
			title : "联系人",
			width : "100px"
		},{
			field : "telephone",
			title : "手机号",
			width : "100px"
		},{
			field : "auditStatus",
			title : "状态",
			width : "60px",
			align : "center",
			formatter : function(value, row, index) {
				if (value == 1) {
					return '<span>未认证</span>';
				}else if (value == 2) {
					return '<span>认证失败</span>';
				}else {
					return '<span>认证成功</span>';
				}
			}
		},{
			field : "name",
			title : "姓名",
			width : "100px"
		}, {
			field : "cardNumber",
			title : "身份证号码",
			width : "100px"
		}, {
			field : "cardFacade",
			title : "身份证正面",
			width : "100px",
			formatter: function (value, row, index) {
				 vm.imgId = value.split(".")[0];
				 console.log(vm.imgId);
                return '<img class ="myImg" id="img_'+vm.imgId+'" src="http://qiniudns.zaishengwang.com/'+value+'"  alt="" onmousemove="vm.scaleImg('+vm.imgId+')" onmouseout="vm.smallImg()">';
            }
		}, {
			field : "cardOpposite",
			title : "身份证反面",
			width : "100px",
			formatter: function (value, row, index) {
				vm.imgId = value.split(".")[0];
				console.log(vm.imgId);
                return '<img class ="myImg" id="img_'+vm.imgId+'" src="http://qiniudns.zaishengwang.com/'+value+'" alt="" onmousemove="vm.scaleImg('+vm.imgId+')" onmouseout="vm.smallImg()">';
             }
		} 
//		, {
//		     field:'ID',
//			 title: '操作',
//		     width: 100,
//			 align: 'center',
//			 valign: 'middle',
//			 formatter: function (value, row, index) {
//                 return '<a v-if="hasPermission()" class="btn btn-default" onclick="vm.edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>';
//             }
//	    }
		
		]
	})
}
var vm = new Vue({
	el : '#dpLTE',
	data : {
		imgId:"",
		keyword : null
	},
	methods : {
		load : function() {
			$('#dataGrid').bootstrapTable('refresh');
		},
		save : function() {
			dialogOpen({
				title : '新增个人',
				url : 'base/userpersonal/add.html?_' + $.now(),
				width : '420px',
				height : '350px',
				yes : function(iframeId) {
					top.frames[iframeId].vm.acceptClick();
				},
			});
		},
		edit : function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections');
			if (checkedRow(ck)) {
				dialogOpen({
					title : '编辑个人',
					url : 'base/userpersonal/edit.html?_' + $.now(),
					width : '420px',
					height : '480px',
					success : function(iframeId) {
						top.frames[iframeId].vm.userpersonal.id = ck[0].id;
						top.frames[iframeId].vm.setForm();
					},
					yes : function(iframeId) {
						top.frames[iframeId].vm.acceptClick();
					}
				});
			}
		},
		remove : function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections'), ids = [];
			if (checkedArray(ck)) {
				$.each(ck, function(idx, item) {
					ids[idx] = item.id;
				});
				$.RemoveForm({
					url : '../../sys/userpersonal/remove?_' + $.now(),
					param : ids,
					success : function(data) {
						vm.load();
					}
				});
			}
		},
		
		scaleImg: function (value){
			$(".shadow").css({
				"display":"block"
			});
			src_ = $("#img_"+value).attr("src");
			$(".myBigImg").attr({"src": src_});
		},
		smallImg: function () {
			$(".shadow").css({
				"display":"none"
			});

		}
	}
})